local redPacket = 'red_packet_hash_' .. KEYS[1]
local stockStr = redis.call('hget', redPacket, 'stock');
if not stockStr then -- 检测key是否存在
    return -1
end

local stock = tonumber(stockStr)
if stock <= 0 then
    return 0
end

stock = stock - 1
redis.call('hset', redPacket, 'stock', tostring(stock))
return stock